package com.ggx.voicereminder;

import java.util.Locale;

import com.ggx.voicereminder.util.LogUtil;

import android.os.Bundle;
import android.app.Activity;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity implements OnInitListener {
	private final String	TAG	= MainActivity.class.getSimpleName();
	private Button			speechButton;
	private EditText		speechText;
	private TextToSpeech	tts;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		tts = new TextToSpeech(this, this);

		speechText = (EditText) findViewById(R.id.edt_input);
		speechButton = (Button) findViewById(R.id.btn_speech);
		speechButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				LogUtil.e(TAG, "speechText:" + speechText.getText().toString());
				// TODO Auto-generated method stub
				tts.speak(speechText.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);
			}
		});
	}

	@Override
	public void onInit(int status) {
		LogUtil.e(TAG, "onInit > status:" + status);
		// TODO Auto-generated method stub
		if (status == TextToSpeech.SUCCESS) {
			int result = tts.setLanguage(Locale.CHINA);
			LogUtil.e(TAG, "onInit > result:" + result);
			if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
				Toast.makeText(MainActivity.this, "Language is not awailable!!!!", Toast.LENGTH_LONG).show();
			}
		}
	}

}
